﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;

namespace app_server
{
    /// <summary>
    /// GetVersion 的摘要说明
    /// </summary>
    public class GetVersion : IHttpHandler
    {
        //app 文件名称
        static string appName = System.Configuration.ConfigurationManager.AppSettings["appName"];

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string path = context.Server.MapPath("apps/" + appName);
                FileVersionInfo fv = FileVersionInfo.GetVersionInfo(path);
                //当前服务器的新版本
                string curVersionStr = fv.ProductVersion;
                Version curVersion = new Version(curVersionStr);

                //客户端正在使用的版本
                string preVersionStr = context.Request["preVersion"];
                Version preVersion = new Version(preVersionStr);
                //版本比较，是否需要更新
                if (curVersion.CompareTo(preVersion) > 0)
                {
                    //需要更新版本
                    context.Response.Write("1");
                }
                else
                {
                    //不需要更新版本
                    context.Response.Write("0");
                }
            }
            catch (Exception e)
            {
                context.Response.Write(e.Message);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}